@extends('layouts.tankuang')

@section('content')
        <form name="add_form" id="add_form" action="{{url('admin/xz/xzadd')}}" method="post" enctype="multipart/form-data">
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <div id="div_print">
                <h2 class="text-center mg_b36 mg_t25" style="font-weight:bold;">金融机构行政许可备案</h2>
                <table class="table-form table-border w mg-auto">
                    <tbody>
                    <tr>
                        <td class="font-bd text-center" width="173">项目名称</td>
                        <td colspan="5"><input type="text" class="form-input w easyui-validatebox" value="" name="name" data-options="required:true,missingMessage:'请填写项目名称',validateOnCreate:false,validateOnBlur:true"></td>
                    </tr>

                     <tr>
                        <td class="font-bd text-center" width="173">申请单位</td>
                        <td>
                            <select id="company" name="unit_id" class="w150 input_all easyui-validatebox" style="width: 174px;" data-options="required:true,missingMessage:'请选择申请单位',validateOnCreate:false,validateOnBlur:true">
                                <option value="">请选择</option>
                                @foreach($company as $v)
                                    <option value="{{$v->id}}">{{$v->name}}</option>
                                @endforeach
                            </select>
                        </td>
                        <td class="font-bd text-center" width="116">上级主管单位</td>
                        <td colspan="3">
                            <input type="text" class="form-input w easyui-validatebox" value="" name="up_unit" data-options="required:true,missingMessage:'请填写上级主管单位',validateOnCreate:false,validateOnBlur:true">
                        </td>
                    </tr>

                    <tr>
                        <td class="font-bd text-center">市、区、派出所</td>
                        <td colspan="5">
                            <div class="col-sm-3" style="margin-left: -15px;">
                                <select id="city" name="city" class="w150 input_all"  style="width: 174px;" disabled>
                                  <!--   <option value="">请选择</option> -->
                                  <!--     @foreach($city as $v)
                                        <option value="{{$v->id}}">{{$v->name}}</option>
                                    @endforeach -->
                                </select>
                            </div>
                            <div class="col-sm-3" style="margin-left: 15px;">
                                <select id="area" name="area" class="w150 input_all" style="width: 174px;" disabled>
                                  <!--   <option value="">请选择</option> -->
                                </select>
                            </div>
                            <div class="col-sm-3" style="margin-left:15px;">
                                <select id="org_id" name="org_id" class="w150 input_all" style="width: 174px;" disabled>
                                  <!--   <option value="">请选择</option> -->
                                </select>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bd text-center">详细地址</td>
                        <td colspan="5"><input type="text" class="form-input w"  value="" name="address" id="address" disabled></td>
                    </tr>
                    <tr>
                        <td class="font-bd text-center">法人代表(主要负责人)</td>
                        <td>
                            <input type="text" class="form-input" value="" name="fzr" id="fzr" disabled style="width: 174px;">
                        </td>
                        <td class="font-bd text-center">联系电话</td>
                        <td colspan="3">
                            <input type="text" class="form-input" value="" name="lxdh" id="lxdh" disabled style="width: 174px;">
                        </td>
                    </tr>
                     <tr>
                        <td class="font-bd text-center">工程类别</td>
                        <td colspan="5"><input name="gclb" type="radio" value="1" />营业场所 &nbsp; <input name="gclb" type="radio" value="2" />金库 &nbsp; <input name="gclb" type="radio" value="3" />自助银行 &nbsp; <input name="gclb" type="radio" value="4" />自助机具</td>
                    </tr

                      <tr>
                        <td class="font-bd text-center">工程属性</td>
                        <td colspan="5"><input name="gcsx" type="radio" value="1" />新建 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input name="gcsx" type="radio" value="2" />改建</td>
                    </tr>
                     <tr>
                        <td class="font-bd text-center">风险等级</td>
                        <td>
                            <input type="text" class="form-input" value="" name="fxdj" style="width: 174px;">
                        </td>
                        <td class="font-bd text-center">防护级别</td>
                        <td colspan="2">
                            <input type="text" class="form-input" value="" name="fhjb" style="width: 174px;">
                        </td>
                    </tr>

                     <tr>
                        <td class="font-bd text-center">报建时间</td>
                        <td>
                            <input type="text" name="bjsj"  class="easyui-datetimebox easyui-validatebox" data-options="required:true,missingMessage:'请输入报建时间',validateOnCreate:false,validateOnBlur:true" />
                        </td>
                        <td class="font-bd text-center">审批时间</td>
                        <td colspan="2">
                            
                            <input type="text" name="spsj"  class="easyui-datetimebox easyui-validatebox" data-options="required:true,missingMessage:'请输入审批时间',validateOnCreate:false,validateOnBlur:true" />
                        </td>
                    </tr>

                     <tr>
                        <td class="font-bd text-center">验收时间</td>
                        <td>
                     
                            <input type="text" name="yssj"  class="easyui-datetimebox easyui-validatebox" data-options="required:true,missingMessage:'请输入验收时间',validateOnCreate:false,validateOnBlur:true" />
                        </td>
                        <td class="font-bd text-center">达标情况</td>
                        <td colspan="2">
                           <input name="is_ok" type="radio" value="1" />合格 &nbsp; <input name="is_ok" type="radio" value="2" />不合格 &nbsp; 
                        </td>
                    </tr>

                    </tbody>
                </table>

            
                <div class="w wbt mg_t25 pd_b20 text-center">
                    <button id="go" type="button" class="easyui-linkbutton dsp" data-options="iconCls:'icon-save'">确定</button>
                    <button type="button" class="easyui-linkbutton dsp" data-options="iconCls:'icon-no'" onclick="$('#w').window('close')">关闭</button>
                </div>
            </div>
        </form>

        <script type="text/javascript">
            $(document).on("change",'#city', function(){

                $('#area option:gt(0)').remove();
                $('#org_id option:gt(0)').remove();
                //alert(1);die;
                var cid = $("#city").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#area").append(option);
                        });
                    }
                });
            });

            $(document).on("change",'#area', function(){
                $('#org_id option:gt(0)').remove();
                var cid = $("#area").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#org_id").append(option);
                        });
                    }
                });
            });
        </script>
        <script>
            $('#go').click(function (){
            	if(!$("#add_form").form('validate')){
				return false;
				}
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "{{url('admin/xz/xzadd')}}",
                    data: $('#add_form').serialize(),
                    async: false,
                    success: function(data) {
                        if(data.status == 1){
                            $.messager.alert('信息提示',data.msg,'info');
                            $('#w').dialog('close');
                            $('.pagination-load').click();
                        }else {
                            $.messager.alert('信息提示',data.msg,'info');
                        }
                    },
                    error: function(msg) {
                        var json=JSON.parse(msg.responseText);
                        $.each(json, function(index, value) {
                            $.messager.alert('信息提示',value,'info');die;
                        });
                    },
                });
            });
        </script>

        <script type="text/javascript">
             $(document).on("change",'#company', function(){
                var url = "{{url('admin/xz/findcompany')}}"
                var id = $("#company").val();
                
                if (id == '') {
                     $('#city option').remove();
                     $('#area option').remove();
                     $('#org_id option').remove();
                     document.getElementById("address").value = '';
                     document.getElementById('fzr').value = '';
                     document.getElementById('lxdh').value = '';

                }



                $.getJSON(url,{id:id},function(json){
                     console.log(json);
                    if (json != '') {
                        //获取详细地址
                        console.log(json['company']['address']);
                        var address = json['company']['address'];
                        document.getElementById("address").value = address;

                        //获取法人
                        var fzr = json['company']['frdb_name'];
                        document.getElementById("fzr").value = fzr;

                        //获取联系方式
                        var lxdh = json['company']['frdb_phone'];
                        document.getElementById('lxdh').value = lxdh;

                        //获取城市
                         $('#city option').remove();
                         $('#area option').remove();
                         $('#org_id option').remove();
                         
                        var option = "<option>"+json['city']['name']+"</option>";
                        $("#city").append(option);

                         var option = "<option>"+json['area']['name']+"</option>";
                        $("#area").append(option);


                         var option = "<option>"+json['org']['name']+"</option>";
                        $("#org_id").append(option);
                       
                    }
                });

            });


        </script>



@stop